package org.freedom.imarket.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.freedom.imarket.dao.UserDAO;
import org.freedom.imarket.entities.User;
import org.freedom.util.CloneHibernate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class AuthenticationController {

	@Autowired
	private UserDAO userDao;

	@RequestMapping(value = "/**/login.do", method = RequestMethod.GET)
	@ResponseBody
	public User doLogin(@RequestParam String username,
			@RequestParam String password, HttpServletRequest req,
			HttpServletResponse response) throws Exception {
		User user = userDao.findUserByUsernameAndPassword(username, password);
		
		// System.out.println(user.getPassword());
		// user.setPassword("pippo");
		// System.out.println(user.getPassword());
		return CloneHibernate.clonePojo(user);
	}

}
